﻿using System.Collections.Generic;
using System.Data.Entity;


namespace Photograp.Models
{
    public class PhotographContext : DbContext
    {
        // You can add custom code to this file. Changes will not be overwritten.
        // 
        // If you want Entity Framework to drop and regenerate your database
        // automatically whenever you change your model schema, add the following
        // code to the Application_Start method in your Global.asax file.
        // Note: this will destroy and re-create your database with every model change.
        // 
        // System.Data.Entity.Database.SetInitializer(new System.Data.Entity.DropCreateDatabaseIfModelChanges<Photograp.Models.PhotographContext>());

        public PhotographContext() : base("PhotographContext")
        {
            this.Configuration.LazyLoadingEnabled = false;
        }

        public DbSet<Album> Albums { get; set; }
        
        public DbSet<UserProfile> UserProfiles { get; set; }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);
            modelBuilder.Conventions.Remove<System.Data.Entity.ModelConfiguration.Conventions.PluralizingTableNameConvention>();


        }

        public void Seed(PhotographContext Context)
        {
            #if DEBUG
            // Create my debug (testing) objects here
            var album = new Album() { Description = "caca", Name= "huete"};
            album.Photos = new List<Photo>();
            album.Photos.Add(new Photo
            {
                Description = "Ma première photo",
                UrlPhoto = @"http://www.sunpeaksresort.com/assets/flora/red_squirrel.jpg"
            });
            album.Photos.Add(new Photo
            {
                Description = "Ma 2 photo",
                UrlPhoto = @"http://www.pestcontrol-uk.org/images/pests/grey-squirrels.jpg"
            });
            album.Photos.Add(new Photo
            {
                Description = "Ma 3 photo",
                UrlPhoto = @"http://brodybrotherspestcontrol.com/assets/images/pests/squirrel.jpg"
            });
            album.Photos.Add(new Photo
            {
                Description = "Ma première photo",
                UrlPhoto = @"http://www.woodlands.co.uk/wordpress/wp-content/uploads/greysquirreldamage.jpg"
            });
            album.Photos.Add(new Photo
            {
                Description = "Ma première photo",
                UrlPhoto = @"http://www.connecticutwilderness.com/images/species/Mammals/200x200/Sciurus_carolinensis_07-27-2011_SWI.jpg"
            });


        
            
            Context.Albums.Add(album);

            

            // Normal seeding goes here
            Context.SaveChanges ();

            #endif
        }

    


    }
}
